﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Sockets;
using System.Text;
using System.Threading;

namespace Sock
{
    class Server
    {
        static int i = 0;
        public static void Main()
        {
            // Config
            XMLParser xmlparser = new XMLParser(@"C:\Configurare.xml");
            Dictionary<string, string> dict = xmlparser.ExtractAttributePairs("Configurare", string.Empty, string.Empty, "name", "formula");

            // Server stuff
            Thread th;
            IPAddress ipAd = IPAddress.Any;
            TcpListener sock = new TcpListener(ipAd, Int32.Parse(dict["ServerMessPort"]));
            sock.Start();
            ManageServerClients msc = new ManageServerClients();
            while (true)
            {
                Console.WriteLine("Waiting for a client...");
                TcpClient client = sock.AcceptTcpClient();
                ClientServerThread cls = new ClientServerThread(client,msc,i++);
                th = new Thread(new ThreadStart(cls.run));
                th.Start();
            }
        }
    }
}
